//
//  MHFMDB+Delete.m
//  数据库的读写封装
//
//  Created by zsgjs on 2017/2/21.
//  Copyright © 2017年 zsgjs. All rights reserved.
//

#import "MHFMDB+Delete.h"
#import "MHFMDB+Querry.h"
@implementation MHFMDB (Delete)

#pragma mark - 删除数据
/**
 *  删除操作
 */
- (BOOL)delete
{
    NSString *sql = [NSString stringWithFormat:@"DELETE FROM `%@` %@",self.currentTableName,self.where];
    return [self excuteUpdateWithSql:sql];
}
/**
 *  根据where条件删除操作
 */
- (BOOL)delete:(id)where
{
    if([where isKindOfClass:[NSString class]]){
        return [[self whereWithString:where] delete];
    }
    if ([where isKindOfClass:[NSDictionary class]]) {
        return [[self whereWithDict:where] delete];
    }
    NSLog(@"PYFMDB WHERE CONDITIONS IS EMPTY,WHERE DATA:%@",where);
    return false;
}

/**
 *  清空数据表
 */
- (void)deleteTableWithTableName:(NSString *)tableName
{
    [self deleteTableWithDict:nil tableName:tableName];
}
/**
 *  公共删除方法
 */
- (void)deleteTableWithDict:(NSDictionary *)dict tableName:(NSString *)tableName
{
    //重置查询条件
    [self clean];
    //选择要操作的表名
    [self setCurrentTableName:tableName];
    //查询数据库是否存在当前待更新的数据源
    [self whereWithDict:dict];
    if ([[self querySigleInfo] count]>0) {
        //存在则删除,dict 为空代表清空整个表
        dict==nil ? [self delete:@"1"]:[self delete:dict];
    }
    //打印sql
    //NSLog(@"currentSql:%@",self.lastSql);
}


@end
